package cn.imvc.app.models;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import cn.imvc.app.commons.SystemConfig;
import cn.imvc.app.entities.Bank;
import cn.imvc.app.repositories.BankRepository;
import cn.imvc.core.ICache;
import cn.imvc.data.domain.ViewRequest;

@Service
public class BankModelImpl implements BankModel {

	@Autowired
	private BankRepository bankRepository;

	@Autowired
	DealerApplyModel dealerApplyModel;

	@Autowired
	MemberModel memberModel;

	@Autowired
	ICache cache;
	
	@Autowired
	SystemConfig systemConfig;


	public Bank get(int id) {
		return bankRepository.findOne(id);
	}

	public Page<Bank> find(ViewRequest viewRequest) {
		return (Page<Bank>) bankRepository.findAll();
	}

	public Bank save(Bank Bank) {

		Bank Bank2 = bankRepository.saveAndFlush(Bank);

		return Bank2;
	}

	public Bank update(Bank newBank) {
		Bank loadBank = get(newBank.getId());
		BeanUtils.copyProperties(newBank, loadBank, new String[] { "id" });

		return bankRepository.saveAndFlush(loadBank);
	}

	public void delete(int id) {
		bankRepository.delete(id);

	}

	public void deleteBatch(int[] ids) {

		for (int id : ids) {
			delete(id);
		}

	}
	
	public List<Bank> findAll(){
		return bankRepository.findAll();
	}

	public List<Bank> findAll(byte isDisabled) {
		return bankRepository.findByIsDisabled(isDisabled);
	}
	

}
